package com.css.zfzx.sjcj.modules.yhdisasiterschedule.dao.pg.impl;

import com.css.zfzx.sjcj.common.Constant;
import com.css.zfzx.sjcj.modules.yhdisasiterschedule.dao.pg.RiskcensusDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import javax.persistence.*;
import java.util.List;

/**
 * @Description: pc-statistics
 * @Author: lhl
 * @CreateDate: 2021/8/31 15:12
 */
@Repository
public class RiskcensusDaoImpl implements RiskcensusDao {
    private EntityManager em;
    
    @Autowired
    public RiskcensusDaoImpl(@Qualifier("postgresqlEntityManager") EntityManager em) {
        this.em = em;
    }

    private static final Logger log = LoggerFactory.getLogger(RiskcensusDaoImpl.class);
    @Override
    public List<Object[]> count(int type,int identify) {
        StringBuilder sql = new StringBuilder("select ");
        if (identify==1){
            sql.append(" fxpc_xzqhbma_sjgl");
        }else if (identify==2){
            sql.append(" fxpc_xzqhbmc_sjgl");
        }
        sql.append(",count(*)");
        if (type==1){
            sql.append(" from "+ Constant.tableName1);
        }else if (type==2){
            sql.append(" from "+ Constant.tableName2);
        }else if (type==3){
            sql.append(" from "+ Constant.tableName3);
        }else if (type==4){
            sql.append(" from "+ Constant.tableName4);
        }else if (type==5){
            sql.append(" from "+ Constant.tableName5);
        }else if (type==6){
            sql.append(" from "+ Constant.tableName6);
        }else if (type==7){
            sql.append(" from "+ Constant.tableName7);
        }
        if (identify==1){
            sql.append(" group by fxpc_xzqhbma_sjgl");
        }else if (identify==2){
            sql.append(" group by fxpc_xzqhbmc_sjgl ");
        }
        Query query = this.em.createNativeQuery(sql.toString());
        return query.getResultList();
    }
}
